package com.aat.dxfy.execOnline.osc;

public class DynaCompTest {
	public static void main(String[] args) throws Exception {
		StringBuilder src = new StringBuilder();
		src.append("public class DynaClass {\n");
		src.append("    public static void main(String[] args) throws Exception {\n");
		src.append("        System.out.println(\"Hello Test Process .\");\n");
		src.append("    }\n");
		src.append("}\n");

		int i1 = src.indexOf("class") + 5;
		int i2 = src.indexOf("{");
		String fullName = src.substring(i1, i2).trim();

		System.out.println(src);
		DynamicEngine de = DynamicEngine.getInstance();
		long start = System.currentTimeMillis(); // 记录开始编译时间
		Object instance = de.javaCodeToObject(fullName, src.toString());
		long end = System.currentTimeMillis();
		System.out.println("编译执行时间:" + (end - start) + "ms");

		System.out.println(instance);
	}

	void test() throws IllegalAccessException, InstantiationException {

		StringBuilder src = new StringBuilder();
		src.append("public class DynaClass {\n");
		src.append("    public String toString() {\n");
		src.append("        return \"Hello, I am \" + ");
		src.append("this.getClass().getSimpleName();\n");
		src.append("    }\n");
		src.append("}\n");

		int i1 = src.indexOf("class") + 5;
		int i2 = src.indexOf("{");
		String fullName = src.substring(i1, i2).trim();

		System.out.println(src);
		DynamicEngine de = DynamicEngine.getInstance();
		long start = System.currentTimeMillis(); // 记录开始编译时间
		Object instance = de.javaCodeToObject(fullName, src.toString());
		long end = System.currentTimeMillis();
		System.out.println("javaCodeToObject use:" + (end - start) + "ms");

		System.out.println(instance);
	}
}
